﻿namespace InfluxDB.Flurl
{
    public class InfluxDbRecord
    {
        public int Table { get; set; }

        public List<string> Keys { get; set; }

        public Dictionary<string, string> Values { get; } = [];

        public DateTimeOffset GetStart()
        {
            return DateTimeOffset.Parse(Values["_start"]);
        }

        public DateTimeOffset GetStop()
        {
            return DateTimeOffset.Parse(Values["_stop"]);
        }

        public DateTimeOffset GetTime()
        {
            return DateTimeOffset.Parse(Values["_time"]);
        }

        public string GetMeasurement()
        {
            return Values["_measurement"];
        }

        public string GetField()
        {
            return Values["_field"];
        }

        public string GetValue()
        {
            return Values["_value"];
        }

        public object GetValueByKey(string key)
        {
            if (Values.TryGetValue(key, out var value))
            {
                return value;
            }

            return null;
        }

    }
}
